
class HotlinkimagePlugin:
	def __init__(self):
		# put all the links this plugins supports here - it will be used to filter supported URLs
		self.supported_sites = ['hotlinkimage.com']
		self.supported_urls = self.supported_sites
		self.cookies_to_block = []

	def get(self, url):
		"""Get a single file from hotlinkimage"""
		parser = URLLister()
		parser.feed(urllib2.urlopen(url).read())
		for script_url in parser.script_urls:
			if script_url.find('hotlinkimage.com/showimg.php') != -1:
				url = script_url
				break
		parser.close()

		src_pat = 'src="'
		# Find the line with our file location
		for line in urllib2.urlopen(url).read().splitlines():
			if line.find(src_pat) != -1:
				url = line.split(src_pat)[1].split('"')[0]
				break

		local_file = get_filename_from_url(url)
		download_file_with_retries(local_file, url)
		config.report.report_finish(local_file)

	def url_matches(self, url):
		"""Check whether we support this URL"""
		parsed_url = urlparse.urlparse(url)
		if parsed_url[2].find('thumb') != -1: # image is a thumbnail
			return False
		for l in self.supported_urls:
			if url.find(l) != -1:
				return True
		return False

	def version(self):
		"""Return plugin version - when interface changes, the version changes"""
		return 1

modules = [HotlinkimagePlugin()]
